// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

// import Tool from "../resources/framework/Tool";
// import sceneMediator from "../resources/framework/sceneMediator";
import value = cc.js.value;
import Tool from "../framework/Tool";
import sceneMediator from "../framework/sceneMediator";
import GameConfig from "../framework/GameConfig";
import mainManage from "../framework/mainManage";
import randomData from "./mainRandomShowRoleSkin/randomData";


export enum TraverStatus {
    unBuild = 0,
    building = 1,
    open = 2,
    close = 3
}

const {ccclass, property} = cc._decorator;

@ccclass
export default class gameData {

    public static processPumpkinNumber = 0;

    public static processPumpkinDate = [];

    public static levelPumpkinDate = [];

    public static pumpkinShowDate = [];

    public static titleStringList = [];

    public static titleDate = [];

    public static princeTitleDate = [];

    public static roleDate = null;

    public static petDate = null;

    public static curTitlePart = 0;

    public static sceneReversal = false;

    public static petSkinList = [0];

    public static curUseSkin = [];

    public static roleSkinList = [1];

    public static curUseRoleSkin = 0;

    public static passEasterEgg = false;

    public static keyUsingIndex = -1;

    public static randomSkinIndex = -1;

    public static isRelive = false;

    public static isRestart = false;

    public static isShowCheats = 0;

    public static showQuestion = [];

    public static clickShowNew = false;

    public static lastColorfulPart = 0;

    public static showMainView = 0;

    public static failGameData = 0;

    public static colorfulPiece = [
        [1,1,1,1,0,0,0],
        [0,0,0,0,0],
        [0,0,0,0,0,0,0],
        [0,0],
        [0,0,0],
        [0,0],
        [0]
    ];

    public static eggWallDate = [];

    public static skinWallDate = [];

    public static backToGame = false;

    public static rebackIsSuccess = false;

    public static titleFreeTimes = 2;

    public static privacyAgreementShow = 0;

    /* ======================= 隐私协议展示 =========================*/
    static getPrivacyAgreementInformation(){
        let data = Tool.getData("privacyAgreement");
        if(data != null && data != "" && data != undefined){
            this.privacyAgreementShow = parseInt(data);
        }else{
            this.privacyAgreementShow = 0;
        }

        console.log("showPrivacy",this.privacyAgreementShow);
    }

    static savePrivacyAgreementInformation(index){
        this.privacyAgreementShow = index;
        Tool.saveData("privacyAgreement",this.privacyAgreementShow);
    }

    static returnPrivacyAgreementInformation(){
        return  this.privacyAgreementShow;
    }
    /* ======================= 隐私协议展示 =========================*/

    /* ======================= 免费提示使用次数 =========================*/
    static saveTitleFreeTiems(){
        Tool.saveData("titleFreeTimes",this.titleFreeTimes);
    }

    static getLocalUseTitleFreeCount(){
        let data = Tool.getData("titleFreeTimes");
        if(data != null && data != "" && data != undefined){
            this.titleFreeTimes = parseInt(data);
        }else{
            this.titleFreeTimes = 0;
        }
    }

    static returnTitleFreeTimes(){
        return this.titleFreeTimes;
    }

    static reduceTitleFreeTimes(){
        this.titleFreeTimes--;
        if(this.titleFreeTimes <= 0){
            this.titleFreeTimes = 0;
        }
        this.saveTitleFreeTiems();
    }
    /* ==========================================================================*/

    /* ======================= 炫彩皮肤碎片 ======================================*/
    static getColorfulPieceNumber(arr){
        let index = 0;
        for(let i in arr){
            if(arr[i] == 1){
                index++;
            }
        }
        return index;
    }

    static saveColorfulPiece(){
        Tool.saveData("ColorSkinPiece",JSON.stringify(this.colorfulPiece));
    }

    static getLocalSkinPieceInformation(){
        let data = Tool.getData("ColorSkinPiece");
        if(data != null && data != "" && data != undefined){
            this.colorfulPiece = JSON.parse(data);
            if(this.colorfulPiece[1] == undefined){
                this.colorfulPiece[1] = [0,0,0,0,0];
            }
            if(this.colorfulPiece[2] == undefined){
                this.colorfulPiece[2] = [0,0,0,0,0,0,0];
            }

            if(this.colorfulPiece[3] == undefined){
                this.colorfulPiece[3] = [0,0];
            }

            if(this.colorfulPiece[4] == undefined){
                this.colorfulPiece[4] = [0,0,0];
            }

            if(this.colorfulPiece[5] == undefined){
                this.colorfulPiece[5] = [0,0];
            }

            if(this.colorfulPiece[6] == undefined){
                this.colorfulPiece[6] = [0];
            }

            if(this.colorfulPiece[7] == undefined){
                this.colorfulPiece[7] = [0];
            }

            if(this.colorfulPiece[8] == undefined){
                this.colorfulPiece[8] = [0];
            }

            if(this.colorfulPiece[9] == undefined){
                this.colorfulPiece[9] = [0];
            }
        }else{
            this.colorfulPiece = [
                [0,0,0,0,0,0,0],
                [0,0,0,0,0],
                [0,0,0,0,0,0,0],
                [0,0],
                [0,0,0],
                [0,0],
                [0], //牛气冲天
                [0], //舞狮
                [0], //福星小牛
                [0]  //熊猫崽崽
            ];
        }
    }

    static saveLastColorfulPart(){
        Tool.saveData("ColorSkin",this.lastColorfulPart);
    }

    static getLocalLastColorSkinInformation(){
        let data = Tool.getData("ColorSkin");
        if(data != null && data != "" && data != undefined){
            this.lastColorfulPart = parseInt(data);
        }else{
            this.lastColorfulPart = 0;
        }
    }

    /* ================================================================================*/

    
    /* ============================== 场景反转 ========================================*/
    static setSceneReversal(value){
        this.sceneReversal = value;
    }

    static getSceneReversal(){
        return this.sceneReversal;
    }
    
    /* ================================== 游戏提示 ======================================*/
    static setCurTitlePart(value){
        this.curTitlePart = value;
    }

    static clearCurTitle(){
        this.curTitlePart = 0;
        this.keyUsingIndex = -1;
        if(!gameData.isRelive){
            if(randomData.getStartUseSkin()){
                if(!randomData.isUseRandomSkin()){
                    if(gameData.getPetProcessSkin()[gameData.randomSkinIndex] == 0){
                        gameData.randomSkinIndex = -1;
                    }
                }
            }else{
                gameData.randomSkinIndex = -1;
            } 
        }
    }

    static getCurTitle(){
        return this.curTitlePart;
    }

    static getCurTitleString(){
        return this.titleStringList;
    }

    /* ================================= 游戏初始数据 ==============================================*/
    static rewardList = null;
    static analysisLocalJsonInformation(){
        Tool.loadDataFromJson("hint_full",(res)=>{
            let levelArr = [];
            for(let i in res){
                if(levelArr.indexOf(res[i]["stage"]) < 0){
                    levelArr.push(res[i]["stage"]);
                }
            }
            console.log(levelArr[levelArr.length - 1]);
            let titleArr = [];
            for(let i = 0 ; i < levelArr[levelArr.length - 1] + 1 ; i++){
                let arr = [];
                for(let j in res){
                    if(res[j]["stage"] == null || res[j]["stage"] == undefined){
                        continue;
                    }else{
                        if(res[j]["stage"] == i){
                            arr.push(res[j]["text"]);
                        }
                    }
                }
                titleArr.push(arr);
            }
            this.titleDate = titleArr;
            console.log("提示标语",this.titleDate);
        });

        Tool.loadDataFromJson("apple_full",(res)=>{
            let arr = [];
            for(let i in res){
                arr.push(res[i]["num"]);
            }
            this.levelPumpkinDate = arr;

            let data = Tool.getData("pumpkinShowDate");
            if(data != null && data != "" && data != undefined){
                this.pumpkinShowDate = JSON.parse(data);
                console.log(this.pumpkinShowDate.length);
                for(let i in this.levelPumpkinDate){
                    if(parseInt(i) < this.pumpkinShowDate.length) continue;
                    let arr1 = [];
                    for(let j = 0; j < this.levelPumpkinDate[i];j++){
                        arr1.push(1);
                    }
                    this.pumpkinShowDate.push(arr1);
                }
            }else{
                for(let i in this.levelPumpkinDate){
                    let arr1 = [];
                    for(let j = 0; j < this.levelPumpkinDate[i];j++){
                        arr1.push(1);
                    }
                    this.pumpkinShowDate.push(arr1);
                }
            }
            console.log(this.pumpkinShowDate.length);
            console.log("苹果数",this.levelPumpkinDate);
            console.log("苹果展示数据",this.pumpkinShowDate);
        });

        Tool.loadDataFromJson("hint2_full",(res)=>{
            let arr = [];
            for(let i in res){
                if(parseInt(i) >= 50){
                    this.princeTitleDate.push(res[i]["text"]);
                }else{
                    arr.push(res[i]["text"]);
                }
            }
            this.titleStringList = arr;
            console.log("提示",this.titleStringList);
            console.log("魔王提示",this.princeTitleDate);
        });

        Tool.loadDataFromJson("roleskin_full",(res)=>{
            this.roleDate = res;
            console.log("商城人物信息",this.roleDate);
        });

        Tool.loadDataFromJson("pet_full",(res)=>{
            this.petDate = res;
            console.log("宠物信息",this.petDate);
        });

        Tool.loadDataFromJson("egg_full",(res)=>{
            for(let i in res){
                if(res[i]["type"] == "彩蛋墙"){
                    this.eggWallDate.push(res[i]);
                }else if(res[i]["type"] == "彩蛋皮肤"){
                    this.skinWallDate.push(res[i]);
                }
            }
            this.getSkinThreadLockData();
            this.getEggThreadLockData();
        });

        Tool.loadDataFromJson("exp_list_full",(res)=>{
            this.expValueList = res;
            console.log("经验列表",this.expValueList);
        });

        Tool.loadDataFromJson("title_list_full",(res)=>{
            this.rankTitleList = res;
            console.log("等级列表",this.rankTitleList)
        });

        Tool.loadDataFromJson("popularRedeem_full",(res)=>{
            this.popularRedeemData = res;
            console.log("通用兑换码",this.popularRedeemData);
            let data = Tool.getData("popularRedeemStatus");
            if(data != null && data != "" && data != undefined){
                this.popularRedeemStatus = JSON.parse(data);
                let curData = JSON.parse(data);
                // 判断是否有新内容
                console.log("本地数据长度：",curData.length,"============","json数据长度：",gameData.getJsonLength(gameData.getPopularRedeemData()));
                // 增加
                if (curData.length < gameData.getJsonLength(gameData.getPopularRedeemData())){
                    console.log("增加本地数据！！！！！！！！！！");
                    for (let i = curData.length ; i < gameData.getJsonLength(gameData.getPopularRedeemData()) ; i ++){
                        console.log(this.popularRedeemStatus);
                        this.popularRedeemStatus[i] = gameData.getPopularRedeemData()[i].status;
                        gameData.saveAllRedeemStatus("popularRedeemStatus",this.popularRedeemStatus);
                    }
                }
                // 删除
                for (let i in gameData.getPopularRedeemData()){
                    if (gameData.getPopularRedeemData()[i].status != 0){
                        this.popularRedeemStatus[i] = gameData.getPopularRedeemData()[i].status;
                        gameData.saveAllRedeemStatus("popularRedeemStatus",this.popularRedeemStatus);
                    }
                }

            }else {
                for (let i = 0 ; i < gameData.getJsonLength(gameData.getPopularRedeemData()) ; i ++){
                    gameData.popularRedeemStatus[i] = gameData.getPopularRedeemData()[i].status;
                    gameData.saveAllRedeemStatus("popularRedeemStatus",this.popularRedeemStatus);
                }
            }
        });
        Tool.loadDataFromJson("conditionalRedeem_full",(res)=>{
            this.conditionalRedeemData = res;
            console.log("条件兑换码",this.conditionalRedeemData);
            let data = Tool.getData("conditionalRedeemStatus");
            if(data != null && data != "" && data != undefined){
                this.conditionalRedeemStatus = JSON.parse(data);
                let curData = JSON.parse(data);
                // 判断是否有新内容
                console.log("本地数据长度：",curData.length,"============","json数据长度：",gameData.getJsonLength(gameData.getConditionalRedeemData()))
                // 增加
                if (curData.length < gameData.getJsonLength(gameData.getConditionalRedeemData())){
                    console.log("增加本地数据！！！！！！！！！！");
                    for (let i = curData.length ; i < gameData.getJsonLength(gameData.getConditionalRedeemData()) ; i ++){
                        console.log(this.conditionalRedeemStatus);
                        this.conditionalRedeemStatus[i] = gameData.getConditionalRedeemData()[i].status;
                        gameData.saveAllRedeemStatus("conditionalRedeemStatus",this.conditionalRedeemStatus);
                    }
                }
                // 删除
                for (let i in gameData.getConditionalRedeemData()){
                    if (gameData.getConditionalRedeemData()[i].status != 0){
                        this.conditionalRedeemStatus[i] = gameData.getConditionalRedeemData()[i].status;
                        gameData.saveAllRedeemStatus("conditionalRedeemStatus",this.conditionalRedeemStatus);
                    }
                }
            }else {
                for (let i = 0 ; i < gameData.getJsonLength(gameData.getConditionalRedeemData()) ; i ++){
                    gameData.conditionalRedeemStatus[i] = gameData.getConditionalRedeemData()[i].status;
                    gameData.saveAllRedeemStatus("conditionalRedeemStatus",this.conditionalRedeemStatus);
                }
            }
        });
        Tool.loadDataFromJson("spin_full",(res)=>{
            this.rewardList = res;
            console.log("转盘",this.rewardList);
        })

    }

    /* ======================= 宠物商店 =========================*/
    public static getPetShopData(){
        return this.petDate;
    }
    /* ======================= 人物商店 =========================*/
    public static getRoleShopData(){
        return this.roleDate;
    }

    /* ======================= 宠物皮肤代码=========================*/
    static setPetCurSkin(value){
        this.curUseSkin = value;
    }

    static getPetCurSkin(){
        return this.curUseSkin;
    }

    public static savePetSkin(index,closeAddExp?){
        // if(closeAddExp){
        //
        // }else{
        //     if(this.petSkinList[index] == 0){
        //         let exp  = gameData.judgeAddExp(index,2);
        //         setTimeout(()=>{
        //             gameData.addExpValue(exp);
        //         },1500);
        //     }
        // }
        this.petSkinList[index] = 1;
        Tool.saveData("petSkin",JSON.stringify(this.petSkinList));
    }

    public static getPetLocalSkinInformation(){
        let data = Tool.getData("petSkin");
        if(data != null && data != "" && data != undefined){
            this.petSkinList = JSON.parse(data);
            if(this.petSkinList.length < 31){
                let index = 31 - this.petSkinList.length;
                for(let i = 0; i < index ;i++){
                    this.petSkinList.push(0);
                }
            }
        }else{
            let index = 31 - this.petSkinList.length;
                for(let i = 0; i < index ;i++){
                    this.petSkinList.push(0);
                }
        }
        console.log(this.petSkinList);
    }

    public static getPetProcessSkin(){
        return this.petSkinList;
    }

    static saveLastPetSkin(){
        Tool.saveData("lastPetSkin",JSON.stringify(this.curUseSkin));
    }

    static getLocalLastPetUseSkinInformation(){
        let data = Tool.getData("lastPetSkin");
        if(data != null && data != "" && data != undefined){
            this.curUseSkin = JSON.parse(data);
        }else{
            this.curUseSkin = [];
        }
    }

    //判断穿戴宠物数量
    static judgeWearPetNumber(rank){
        return 1;
        // return (rank + 2);
    }
    /* ============================================================*/

    /* ======================= 角色皮肤代码=========================*/
    public static getRoleProcessSkin(){
        return this.roleSkinList;
    }

    public static getRoleLocalSkinInformation(){
        let data = Tool.getData("roleSkin");
        if(data != null && data != "" && data != undefined){
            this.roleSkinList = JSON.parse(data);
            if(this.roleSkinList.length < 22){
                let data = 22 - this.roleSkinList.length;
                for(let i = 0 ; i < data; i++){
                    this.roleSkinList.push(0);
                }
            }
        }else{
            for(let i = 0; i < data ;i++){
                this.roleSkinList.push(0);
            }
        }
        console.log(this.roleSkinList);
    }

    public static saveRoleSkin(index,closeAddExp?){
        //加经验
        // if(closeAddExp){
        //
        // }else{
        //     if(this.roleSkinList[index] == 0){
        //         let exp  = gameData.judgeAddExp(index,1);
        //         setTimeout(()=>{
        //             gameData.addExpValue(exp);
        //         },1500);
        //     }
        // }
        this.roleSkinList[index] = 1;
        Tool.saveData("roleSkin",JSON.stringify(this.roleSkinList));
    }

    public static getCurUseRoleSkin(){
        return this.curUseRoleSkin;
    }

    public static setCurUseRoleSkin(value){
        this.curUseRoleSkin = value;
        gameData.randomSkinIndex = -1;
    }

    static saveLastRoleSkin(){
        Tool.saveData("lastRoleSkin",this.curUseRoleSkin);
    }

    static getLocalLastRoleUseSkinInformation(){
        let data = Tool.getData("lastRoleSkin");
        if(data != null && data != "" && data != undefined){
            this.curUseRoleSkin = parseInt(data);
        }else{
            this.curUseRoleSkin = 0;
        }
    }
    /* ===========================================================*/

    /* ======================= 提示代码 ==========================*/
    public static getTitleData(scene,part?){
        this.curTitlePart++;
        let stringList = this.titleDate[scene][this.curTitlePart - 1];
        if(typeof part != "undefined"){
            stringList = this.titleDate[scene][part];
        }
        if(typeof stringList == "undefined"){
            stringList = "";
        }
        return stringList;
    }

    public static getPrinceTitleDate(){
        return this.princeTitleDate;
    }
    /* ===========================================================================*/

    /* ============================ 游戏中苹果相关数据 =============================*/
    public static savePumpkinDate(){
        let data = JSON.stringify(this.processPumpkinDate);
        Tool.saveData("PumpkinDates",data);
    }

    public static getLocalEveryLevelAppleInformation(){
        let data = Tool.getData("PumpkinDates");
        if(data != null && data != "" && data != undefined){
            this.processPumpkinDate = JSON.parse(data);
            for(let i = 0 ; i < 60 - this.processPumpkinDate.length ; i++){
                this.processPumpkinDate.push(0);
            }
        }else{
            for(let i = 0 ; i < 60 ;i++){
                this.processPumpkinDate.push(0);
            }
        }
    }
  
    static getPumpkinShowDate(){
        return this.pumpkinShowDate;
    }

    public static savePumpkinShowDate(){
        Tool.saveData("pumpkinShowDate",JSON.stringify(this.pumpkinShowDate));
    }

    static getProcessPumpkin(){
        return this.processPumpkinDate;
    }

    static getLevelPumpkin(){
        return this.levelPumpkinDate;
    }

    static savePumpkinNumber(){
        Tool.saveData("pumpkinNumber",this.processPumpkinNumber);
    }

    static getLocalTotalAppleInformation(){
        let data = Tool.getData("pumpkinNumber");
        if(data != null && data != "" && data != undefined){
            this.processPumpkinNumber = parseInt(data);
        }else{
            this.processPumpkinNumber = 0;
        }
    }

    static getCurPumpkinNumber(){
        return this.processPumpkinNumber;
    }

    static costPumpkinNumber(value){
        this.processPumpkinNumber -= value;
        this.savePumpkinNumber();
    }

    static addPumpkin(){
        let scene = 0;
        if(sceneMediator.curEnterLevel == 0){
            scene = sceneMediator.getShowScene();
        }else{
            scene = 50 + sceneMediator.princeShowLevel;
        }
        if(scene <= this.processPumpkinDate.length){
            if(this.processPumpkinDate[scene - 1] < this.levelPumpkinDate[scene - 1]){
                this.processPumpkinDate[scene - 1] += 1;
            }
        }else{
            this.processPumpkinDate.push(1);
        }
        this.savePumpkinDate();
        this.processPumpkinNumber++;
        this.savePumpkinNumber();
    }

    static addSinglePumpkin(index?){
        if(index){
            this.processPumpkinNumber += index;
        }else{
            this.processPumpkinNumber++;
        }
        this.savePumpkinNumber();
    }

    public static showRewardApple = false;
    static getLocalShowRewardAppleInformation(){
        let data = Tool.getData("showRewardApple");
        if(data != null && data != "" && data != undefined){
            if(parseInt(data) == 0){
                this.showRewardApple = false;
            }else{
                this.showRewardApple = true;
            }
        }else{
            this.showRewardApple = false;
        }
    }

    static saveShowRewardApple(){
        this.showRewardApple = true;
        Tool.saveData("showRewardApple",1);
    }

    /* ============================ 游戏中彩蛋相关数据 =============================*/
    public static getSpecialEasterEggInformation(){
        let data = Tool.getData("EasterEgg");
        if(data != null && data != "" && data != undefined){
            if(data == 0){
                this.passEasterEgg = true;
            }else{
                this.passEasterEgg = false;
            }
        }else{
            this.passEasterEgg = true;
        }
    }

    public static saveEasterEgg(){
        let data = 0;
        if(this.passEasterEgg){
            data = 0;
        }else{
            data = 1;
        }
        Tool.saveData("EasterEgg",data);
    }


    static eggSkinList = [0,0,0];
    static getLocalEggSkinInformation(){
        let data = Tool.getData("eggSkinList");
        if(data != null && data != "" && data != undefined){
            this.eggSkinList = JSON.parse(data);
            if(this.eggSkinList.length < 3){
                for(let i = 0 ; i < 3 - this.eggSkinList.length ;i++){
                    this.eggSkinList.push(0);
                }
            }
        }else{
            this.eggSkinList = [0,0,0];
        }
    }

    static saveEggSkinList(){
        Tool.saveData("eggSkinList",JSON.stringify(this.eggSkinList));
    }

    /* ===========================================================================*/

    /* ============================ 补偿奖励 =============================*/
    static seeVideoTimes = [0,0,0];
    static getLocalWatchVideoTimesInformation(){
        let data = Tool.getData("getSeeVideoTimes");
        if(data != null && data != "" && data != undefined){
            this.seeVideoTimes = JSON.parse(data);
        }else{
            this.seeVideoTimes = [0,0,0];
        }
        return this.seeVideoTimes;
    }

    static saveSeeVideoTimes(){
        Tool.saveData("getSeeVideoTimes",JSON.stringify(this.seeVideoTimes));
    }

    /* ============================ 彩蛋墙 =====================================================*/
    public static skinThreadLockData = [];
    static getSkinThreadLockData(){
        let data = Tool.getData("skinThreadLockData");
        if(data != null && data != "" && data != undefined){
            let index = JSON.parse(data);
            if(typeof index[0][0] == "undefined"){
                for(let i in this.skinWallDate){
                    let arr = [];
                    let number = this.skinWallDate[i]["keynum"];
                    for(let j = 0 ; j < number ;j++){
                        arr.push(0);
                    }
                    this.skinThreadLockData.push(arr);
                }
            }else{
                this.skinThreadLockData = JSON.parse(data);
                let skinData = JSON.parse(data);
                let length = skinData.length;
                for(let i in this.skinWallDate){
                    let arr = [];
                    if(typeof this.skinWallDate[parseInt(i) + length] != "undefined" && this.skinWallDate[parseInt(i) + length]){
                        let number = this.skinWallDate[parseInt(i) + length]["keynum"];
                        for(let j = 0 ; j < number ;j++){
                            arr.push(0);
                        }
                        this.skinThreadLockData.push(arr);
                    }else{
                        continue;
                    }
                }
            }
            console.log("皮肤线索列表2",this.skinThreadLockData);
        }else{
            for(let i in this.skinWallDate){
                let arr = [];
                let number = this.skinWallDate[i]["keynum"];
                for(let j = 0 ; j < number ;j++){
                    arr.push(0);
                }
                this.skinThreadLockData.push(arr);
            }
            console.log("皮肤线索列表1",this.skinThreadLockData);
        }
    }

    static saveGetSkinThreadLockData(){
        Tool.saveData("skinThreadLockData",JSON.stringify(this.skinThreadLockData));
    }

    public static eggThreadLockData = [];
    static getEggThreadLockData(){
        let data = Tool.getData("eggThreadLockData");
        if(data != null && data != "" && data != undefined){
            let index = JSON.parse(data);
            if(typeof index[0][0] == "undefined"){
                for(let i in this.eggWallDate){
                    let arr = [];
                    let number = this.eggWallDate[i]["keynum"];
                    for(let j = 0 ; j < number ;j++){
                        arr.push(0);
                    }
                    this.eggThreadLockData.push(arr);
                }
            }else{
                this.eggThreadLockData = JSON.parse(data);
                let skinData = JSON.parse(data);
                let length = skinData.length;
                for(let i in this.eggWallDate){
                    let arr = [];
                    if(typeof this.eggWallDate[parseInt(i) + length] != "undefined" && this.eggWallDate[parseInt(i) + length]){
                        let number = this.eggWallDate[parseInt(i) + length]["keynum"];
                        for(let j = 0 ; j < number ;j++){
                            arr.push(0);
                        }
                        this.eggThreadLockData.push(arr);
                    }else{
                        continue;
                    }
                }
            }
            console.log("彩蛋线索列表",this.eggThreadLockData);
        }else{
            for(let i in this.eggWallDate){
                let arr = [];
                let number = this.eggWallDate[i]["keynum"];
                for(let j = 0 ; j < number ;j++){
                    arr.push(0);
                }
                this.eggThreadLockData.push(arr);
            }
            console.log("彩蛋线索列表",this.eggThreadLockData);
        }
    }

    static saveGetEggThreadLockData(){
        Tool.saveData("eggThreadLockData",JSON.stringify(this.eggThreadLockData));
    }

     /* ============================ 兑换码 =====================================================*/
    static redeemCode = [
        ["胖胖龙","ppl"],
        ["飞天西瓜猪","xgz"],
        ["炫彩太空人","tkr"],
        ["狗头大师","gtds"],
        ["电机战士","sjzs"],
        ["袜子勇士","wzys"],
        ["100个苹果","apple100"],
        ["飞天西瓜猪","94482"],
        ["BUG君","bug"]
    ];
    static redeemStatus = [0,0,0,0,0,0,0,0];
    static getLocalRedeemStatusInformation(){
        let data = Tool.getData("RedeemStatus");
        if(data != null && data != "" && data != undefined){
            this.redeemStatus = JSON.parse(data);
        }else{
            this.redeemStatus = [0,0,0,0,0,0,0,0];
        }
    }
    static saveRedeemStatus(){
        Tool.saveData("RedeemStatus",JSON.stringify(this.redeemStatus));
    }

    private static popularRedeemData = null;
    static popularRedeemStatus = [];
    public static getPopularRedeemData(){
        return this.popularRedeemData;
    }

    private static conditionalRedeemData = null;
    static conditionalRedeemStatus = [];
    public static getConditionalRedeemData(){
        return this.conditionalRedeemData;
    }

    static saveAllRedeemStatus(redeemKey,redeemStatus){
        Tool.saveData(redeemKey,JSON.stringify(redeemStatus));
    }

    static curRedeemSuccessId = -1;
    // 0:宠物 1:人物 2:苹果 3:奖券 4:龙珠 5 : 紫色碎片
    static curRedeemSuccessType;
    static getCurSuccessRedeemInfo(curID,type){
        console.log("获取奖励信息");
        if (type == 0){
            gameData.curRedeemSuccessId = parseInt(gameData.getPetShopData()[curID].id);
            console.log("获取当前宠物ID",gameData.curRedeemSuccessId);
            gameData.curRedeemSuccessType = 0;
        }else if (type == 1){
            gameData.curRedeemSuccessId = parseInt(gameData.getRoleShopData()[curID].id);
            console.log("获取当前人物ID",gameData.curRedeemSuccessId);
            gameData.curRedeemSuccessType = 1;
        }else if (type == 2){
            gameData.curRedeemSuccessType = 2;
        }else if (type == 3){
            gameData.curRedeemSuccessType = 3;
        }else if (type == 4){
            gameData.curRedeemSuccessType = 4;
        }else if (type == 5){
            gameData.curRedeemSuccessType = 5;
        }
    }

    static getJsonLength(jsonData){
        let jsonLength = 0;
        for (let i in jsonData){
            jsonLength ++;
        }
        return jsonLength;
    }

    static localData = {
        showMainView : false,
        clickShowNew : false,
        showAttention : false,
        showConversation : false,
        showRewardApple : false,
        easterEgg : false,
        processPumpkinDate : [],
        pumpkinShowDate : [],
        processPumpkinNumber : 0,
        petSkin : [0],
        roleSkin : [1],
        lastRoleSkin : 0,
        lastPetSkin : [],
        colorfulPiece :[[0,0,0,0,0,0,0],[0,0,0,0,0]],
        lastColorful : [],  // -1为默认皮肤 没有皮肤炫彩
        redeemStatus : [],
        eggThreadLockData : [],
        skinThreadLockData : [],
        seeVideoTimes : [],
        eggSkinList : [],
    };

    /* ============================ 特殊关卡机关 =====================================================*/
    //触发时空机关
    static openTimesSwtich = false;

    static getLocalSpecialLevelInformation(){
        let data = Tool.getData("princeLevelData");
        if(data != null && data != "" && data != undefined){
            let arr = JSON.parse(data);
            this.showConversation = arr[0];
            this.unlockPrinceStone5 = arr[1];
            if(arr[2] == null || arr[2] == undefined || arr[2] == ""){
                this.showConversation8 = false;
            }else{
                this.showConversation8 = arr[2];
            }

            if(arr[3] == null || arr[3] == undefined || arr[3] == ""){
                this.showConversation81 = false;
            }else{
                this.showConversation81 = arr[3];
            }

            if(arr[4] == null || arr[4] == undefined || arr[4] == ""){
                this.showConversation82 = false;
            }else{
                this.showConversation82 = arr[4];
            }

            if(arr[5] == null || arr[5] == undefined || arr[5] == ""){
                this.seeThreadPrince82 = false;
            }else{
                this.seeThreadPrince82 = arr[5];
            }

            if(arr[6] == null || arr[6] == undefined || arr[6] == ""){
                this.seeThreadVideoPrince82 = false;
            }else{
                this.seeThreadVideoPrince82 = arr[6];
            }
        }else{
            this.showConversation = false;
            this.unlockPrinceStone5 = false;
            this.showConversation8 = false;
            this.showConversation81 = false;
            this.showConversation82 = false;
            this.seeThreadPrince82 = false;
            this.seeThreadVideoPrince82 = false;
        }
    }

    static savePrinceLevelLocalPart1(){
        let data = [
            this.showConversation,
            this.unlockPrinceStone5,
            this.showConversation8,
            this.showConversation81,
            this.showConversation82,
            this.seeThreadPrince82,
            this.seeThreadVideoPrince82
        ];
        Tool.saveData("princeLevelData",JSON.stringify(data));

    }

    static showConversation = false;

    static unlockPrinceStone5 = false;

    static showConversation8 = false;

    static showConversation81 = false;

    static showConversation82 = false;

    static seeThreadPrince82 = false;

    static seeThreadVideoPrince82 = false;

    static  lastColorfulList = [0,0,0];

    static saveLastColorfulList(){
        let data = this.lastColorfulList;
        Tool.saveData("LastColorSkin",JSON.stringify(data));
    }

    static getLocalLastUseColorSkinInformation(){
        let data = Tool.getData("LastColorSkin");
        if(data != null && data != "" && data != undefined){
            let arr = JSON.parse(data);
            this.lastColorfulList = arr;
            if(this.lastColorfulList.length < 3){
                let data = 3 - this.lastColorfulList.length;
                for(let i = 0; i < data ;i++){
                    this.lastColorfulList.push(0);
                }
            }
        }else{
            this.lastColorfulList = [0,0,0];
        }
        console.log(this.lastColorfulList);
    }

    /* ============================ 抽奖界面 =====================================================*/
    //拥有的奖券数量
    static lotteryTicket = 0;
    //免费的奖券
    static freeLotteryTimes= 0;
    //上次抽奖时间
    static lastLotteryTimes = 0;
    //上次分享次数
    static shareVideoTimes = 0;
    //上次登录时间点
    static lastLoginTimes = [];
    //看视频抽奖次数
    static seeVideoGetTicket = 0;
    //宠物碎片
    static petPiece = 0;
    //每天抽奖上线
    static playLotteryLimit = 0;
    //兑换码的使用次数
    static redeemCodeUseTimes = 0;

    static getLocalLotteryViewInformation(){
        let data = Tool.getData("lotteryData");
        if(data != null && data != "" && data != undefined){
            let index = JSON.parse(data);
            if(GameConfig.GetInstance().version == "play"){
                this.lotteryTicket = 200;
            }else{
                this.lotteryTicket = index[0];
            }
            // this.lotteryTicket = index[0];
            this.lastLotteryTimes = index[1];
            this.shareVideoTimes = index[2];
            this.seeVideoGetTicket =  index[3];
            this.lastLoginTimes = index[4];
            this.freeLotteryTimes = index[5];
            this.petPiece = index[6];

            if(index[7] != null && index[7] != "" && index[7] != undefined){
                this.playLotteryLimit = index[7] ;
            }else{
                this.playLotteryLimit = 0 ;
            }

            if(index[8] != null && index[8] != "" && index[8] != undefined){
                this.redeemCodeUseTimes = index[8] ;
            }else{
                this.redeemCodeUseTimes = 0;
            }


            let day = new Date().getDay();
            let month = new Date().getMonth();
            if(this.lastLoginTimes[0] == month){
                if(this.lastLoginTimes[1] != day){
                    this.shareVideoTimes = 0;
                    this.lastLotteryTimes = 0;
                    this.seeVideoGetTicket = 0;
                    this.playLotteryLimit = 0;
                    this.freeLotteryTimes = 3;
                    this.redeemCodeUseTimes = 0;
                    this.lastLoginTimes = [month,day];
                }
            }else if(month > this.lastLoginTimes[0]){
                this.shareVideoTimes = 0;
                this.lastLotteryTimes = 0;
                this.seeVideoGetTicket = 0;
                this.playLotteryLimit = 0;
                this.redeemCodeUseTimes = 0;
                this.freeLotteryTimes = 3;
                this.lastLoginTimes = [month,day];
            }
        }else{
            if(GameConfig.GetInstance().version == "play"){
                this.lotteryTicket = 200;
            }else{
                this.lotteryTicket = 0;
            }
            this.lastLotteryTimes = 0;
            this.shareVideoTimes = 0;
            this.seeVideoGetTicket = 0;
            this.redeemCodeUseTimes = 0;
            this.playLotteryLimit = 0;
            this.freeLotteryTimes = 3;
            this.lastLoginTimes = [new Date().getMonth(),new Date().getDay()];
            this.petPiece = 0;
        }
        console.log("拥有的奖券数量",this.lotteryTicket);
        console.log("上次抽奖的时间",this.lastLotteryTimes);
        console.log("分享的次数",this.shareVideoTimes);
        console.log("抽奖的次数",this.seeVideoGetTicket);
        console.log("免费抽奖的次数",this.freeLotteryTimes);
        console.log("上次抽奖的时间点",this.lastLoginTimes);
        console.log("宠物碎片",this.petPiece);
        console.log("抽奖次数限制",this.playLotteryLimit);
        console.log("兑换码使用次数",this.redeemCodeUseTimes);
    }

    static saveLotteryData(){
        let data = [
            this.lotteryTicket,
            this.lastLotteryTimes,
            this.shareVideoTimes,
            this.seeVideoGetTicket,
            this.lastLoginTimes,
            this.freeLotteryTimes,
            this.petPiece,
            this.playLotteryLimit,
            this.redeemCodeUseTimes
        ];
        Tool.saveData("lotteryData",JSON.stringify(data));
    }


    /* ============================ 其他游戏数据 =====================================================*/
    static saveOtherGameData(){
        let data = [
            this.duckToolStatus,
            this.unlockTavern,
            this.expValue,
            this.curRankTitle,
            this.normalLevelExp,
            this.specialLevelExp,
            this.wearingTitle,
            this.rewardVideoTimes,
            this.appleGetList,
            this.finalAppleGet,
            this.seeVideoLockSkin,
            this.newYearPetLockStatus,
            this.newYearPetUseStatus,
            this.continuousLoginDay,
            this.lastContinuousLoginTimes,
            this.newYearEggSeeVideoTimes,
            this.newYearColorfulVideoTimes,
            this.duckGetAppleAndTicket,
            this.newYearPetSelectStatus
        ];
        Tool.saveData("gameDate",JSON.stringify(data));
    }

    //鸭子道具的出现状态
    static duckToolStatus = [0,0,0];

    //解锁酒馆
    static unlockTavern = false;

    //冒险家等级经验值
    static expValue  = 0;

    //当前冒险家称号
    static curRankTitle = 0;

    //经验值列表
    static expValueList = [];

    //冒险家等级列表
    static rankTitleList = [];

    //普通关卡经验
    static normalLevelExp = [];

    //特殊关卡经验
    static specialLevelExp = [];

    //是否穿戴冒险家称号
    static wearingTitle = false;

    //获取信物阿七两种信物看视频次数
    static rewardVideoTimes = [0,0];

    //小飞鸡关卡苹果是否领取记录
    static appleGetList = [0,0,0];

    //小飞鸡关卡结算苹果是否领取苹果
    static finalAppleGet = false;

    //小飞鸡关卡获得信物是否看视频解锁
    static seeVideoLockSkin = [0,0];

    //春节宠物皮肤解锁状态
    static newYearPetLockStatus = [];

    //春节宠物皮肤使用状态
    static newYearPetUseStatus = [];

    //春节大狂欢连续天数
    static continuousLoginDay = 0;

    //春节大狂欢上次登录时间点
    static lastContinuousLoginTimes = [];

    //春节牛气冲天彩蛋看视频次数
    static newYearEggSeeVideoTimes = 0;

    //春节大狂欢 舞狮,福星小牛,熊猫崽崽
    static newYearColorfulVideoTimes = [0,0,0];

    //抓鸭子获得奖券和苹果的每天次数
    static duckGetAppleAndTicket = [0,0];

    //春节宠物界面当前皮肤选择状态
    static newYearPetSelectStatus = [];

    //添加经验
    static addExpValue(value){
        this.expValue += value;
        this.saveOtherGameData();
        if(this.expValue >= gameData.rankTitleList[this.curRankTitle + 1]["exp"]){
            this.curRankTitle += 1;
            cc.game.emit("resetAdvenTitle");
            mainManage.createToast("恭喜获得" + this.rankTitleList[this.curRankTitle]["name"] + "的称号,并可以携带" + (this.curRankTitle + 2) + "宠物");
        }
    }

    //判断是否可以加经验
    // 1 : 人物  2 : 宠物  3 : 普通关卡  4 : 特殊关卡  5 :福利奖励  6 : 所有皮肤  7 : 所有宠物
    static judgeAddExp(value,type){
        let isAdd = 0;
        if(type == 1){
            if(typeof  value == "number"){
                for(let i in gameData.expValueList){
                    if(gameData.expValueList[i]["nema"] == gameData.getRoleShopData()[value]["rsname"]){
                        isAdd = gameData.expValueList[i]["exp"];
                        break;
                    }
                }
            }else if(typeof value == "string"){
                for(let i in gameData.expValueList){
                    if(gameData.expValueList[i]["nema"] == value){
                        isAdd = gameData.expValueList[i]["exp"];
                        break;
                    }
                }
            }
        }else if(type == 2){
            if(typeof  value == "number"){
                for(let i in gameData.expValueList){
                    if(gameData.expValueList[i]["nema"] == gameData.getPetShopData()[value]["psname"]){
                        isAdd = gameData.expValueList[i]["exp"];
                        break;
                    }
                }
            }else if(typeof value == "string"){
                for(let i in gameData.expValueList){
                    if(gameData.expValueList[i]["nema"] == value){
                        isAdd = gameData.expValueList[i]["exp"];
                        break;
                    }
                }
            }
        }else if(type == 3){
            if(gameData.normalLevelExp[value] == 0){
                isAdd = 1;
                gameData.normalLevelExp[value] = 1;
            }
        }else if(type == 4){
            if(gameData.specialLevelExp[value] == 0){
                isAdd = 2;
                gameData.specialLevelExp[value] = 1;
            }
        }else if(type == 5){
            isAdd = sceneMediator.getMaxLevel() - sceneMediator.getHighScene();
        }else if(type == 6){
            let arr = [];
            for(let i in gameData.getRoleShopData()){
                if(parseInt(i) < 9){
                    arr.push(gameData.getRoleShopData()[i]["rsname"]);
                }
            }
            for(let i in gameData.expValueList){
                if(arr.indexOf(gameData.expValueList[i]["nema"]) > -1){
                    isAdd += gameData.expValueList[i]["exp"];
                }
            }

        }else if(type == 7){

            let arr = [];
            for(let i in gameData.getRoleShopData()){
                if(parseInt(i) < 14){
                    arr.push(gameData.getPetShopData()[i]["psname"]);
                }
            }
            for(let i in gameData.expValueList){
                if(arr.indexOf(gameData.expValueList[i]["nema"]) > -1){
                    isAdd += gameData.expValueList[i]["exp"];
                }
            }
        }
        mainManage.createToast("恭喜获得" + isAdd + "经验值");
        return isAdd;
    }

    static getLocalOtherGameInformation(){
        let data = Tool.getData("gameDate");
        if(data != null && data != "" && data != undefined){
            let index = JSON.parse(data);
            this.duckToolStatus = index[0];

            if(index[1] != null && index[1] != "" && index[1] != undefined){
                this.unlockTavern = index[1] ;
            }else{
                this.unlockTavern = false;
            }

            if(index[2] != null && index[2] != "" && index[2] != undefined){
                this.expValue = index[2] ;
            }else{
                this.expValue = 0;
            }

            if(index[3] != null && index[3] != "" && index[3] != undefined){
                this.curRankTitle = index[3] ;
            }else{
                this.curRankTitle = 0;
            }

            if(index[4] != null && index[4] != "" && index[4] != undefined){
                this.normalLevelExp = index[4] ;
            }else{
                for(let i = 0; i < 50 ;i++){
                    this.normalLevelExp.push(0);
                }
            }

            if(index[5] != null && index[5] != "" && index[5] != undefined){
                this.specialLevelExp = index[5] ;
            }else{
                for(let i = 0; i < 50 ;i++){
                    this.specialLevelExp.push(0);
                }
            }

            if(index[6] != null && index[6] != "" && index[6] != undefined){
                this.wearingTitle = index[6] ;
            }else{
                this.wearingTitle = false;
            }

            if(index[7] != null && index[7] != "" && index[7] != undefined){
                this.rewardVideoTimes = index[7] ;
            }else{
                this.rewardVideoTimes =  [0,0];
            }

            if(index[8] != null && index[8] != "" && index[8] != undefined){
                this.appleGetList = index[8] ;
            }else{
                this.appleGetList =  [0,0,0];
            }

            if(index[9] != null && index[9] != "" && index[9] != undefined){
                this.finalAppleGet = index[9] ;
            }else{
                this.finalAppleGet =  false;
            }

            if(index[10] != null && index[10] != "" && index[10] != undefined){
                this.seeVideoLockSkin = index[10] ;
            }else{
                this.seeVideoLockSkin = [0,0];
            }

            if(index[11] != null && index[11] != "" && index[11] != undefined){
                this.newYearPetLockStatus = index[11] ;
                let data = this.newYearPetUseStatus.length;
                for(let i = 0; i < 31 - data ; i++){
                    this.newYearPetLockStatus.push(0);
                }
            }else{
                for(let i = 0 ; i < 31; i++){
                    this.newYearPetLockStatus.push(0);
                }
            }

            if(index[12] != null && index[12] != "" && index[12] != undefined){
                this.newYearPetUseStatus = index[12] ;
                let data = this.newYearPetUseStatus.length;
                for(let i = 0; i < 31 -  data; i++){
                    this.newYearPetUseStatus.push(0);
                }
            }else{
                for(let i = 0 ; i < 31; i++){
                    this.newYearPetUseStatus.push(0);
                }
            }

            if(index[13] != null && index[13] != "" && index[13] != undefined){
                this.continuousLoginDay = index[13] ;
            }else{
                this.continuousLoginDay = 0;
            }

            if(index[14] != null && index[14] != "" && index[14] != undefined){
                this.lastContinuousLoginTimes = index[14];
            }else{
                this.lastContinuousLoginTimes = [new Date().getMonth() + 1,new Date().getDate()];
                this.saveOtherGameData()
            }

            if(index[15] != null && index[15] != "" && index[15] != undefined){
                this.newYearEggSeeVideoTimes = index[15] ;
            }else{
                this.newYearEggSeeVideoTimes = 0;
            }

            if(index[16] != null && index[16] != "" && index[16] != undefined){
                this.newYearColorfulVideoTimes = index[16] ;
            }else{
                this.newYearColorfulVideoTimes = [0,0,0];
            }

            if(index[17] != null && index[17] != "" && index[17] != undefined){
                this.duckGetAppleAndTicket = index[17] ;
                let month = new Date().getMonth() + 1;
                let day = new Date().getDate();
                if(month != this.duckGetAppleAndTicket[0]){
                    this.duckGetAppleAndTicket[2] = 0;
                }else if(month == this.duckGetAppleAndTicket[0] && day != this.duckGetAppleAndTicket[1]){
                    this.duckGetAppleAndTicket[2] = 0;
                }
                this.duckGetAppleAndTicket[0] =  month;
                this.duckGetAppleAndTicket[1] = day;
                console.log("抓鸭子次数",this.duckGetAppleAndTicket);
            }else{
                this.duckGetAppleAndTicket = [new Date().getMonth() + 1,new Date().getDate(),0];
            }

            if(index[18] != null && index[18] != "" && index[18] != undefined){
                this.newYearPetSelectStatus = index[18] ;
                let data = this.newYearPetSelectStatus.length;
                for(let i = 0; i < 31 -  data; i++){
                    this.newYearPetSelectStatus.push(0);
                }
            }else{
                for(let i = 0 ; i < 31; i++){
                    this.newYearPetSelectStatus.push(0);
                }
            }
        }else{
            this.duckToolStatus = [0,0,0];
            this.unlockTavern = false;
            this.expValue = 0;
            this.curRankTitle = 0;
            this.wearingTitle = false;
            this.rewardVideoTimes = [0,0];
            this.appleGetList =  [0,0,0];
            this.seeVideoLockSkin = [0,0];
            this.finalAppleGet = false;
            this.continuousLoginDay = 0;
            this.newYearEggSeeVideoTimes = 0;
            this.newYearColorfulVideoTimes = [0,0,0];
            this.duckGetAppleAndTicket = [0,0,0];
            this.lastContinuousLoginTimes = [new Date().getMonth() + 1,new Date().getDate()];
            for(let i = 0 ; i < 31; i++){
                this.newYearPetLockStatus.push(0);
            }
            for(let i = 0 ; i < 31; i++){
                this.newYearPetUseStatus.push(0);
            }

            for(let i = 0 ; i < 31; i++){
                this.newYearPetSelectStatus.push(0);
            }

            for(let i = 0; i < 50 ;i++){
                this.normalLevelExp.push(0);
                this.specialLevelExp.push(0);
            }
            this.saveOtherGameData()
        }
    }


    //判断是否到时间了
    static judgeTimeCome(finalTime,successCallback,failCallback){
        if(GameConfig.GetInstance().version == "play"){
            successCallback();
        }else{
            let month = 0;
            let day = 0;
            if(!this.openSetTime){
                month = new Date().getMonth() + 1;
                day = new Date().getDate();
            }else{
                month = 2;
                day = this.curSetTime;
            }
            if((month == 2 && day >= finalTime) || month > 2){
                successCallback();
            }else{
                failCallback();
            }
        }
    }

    //手动设置今日的时间
    static curSetTime = 0;
    static openSetTime = false;

    static setCurrentTimes(day){
        this.openSetTime = true;
        this.curSetTime = day;
        if(this.lastContinuousLoginTimes[0] != 2 && (this.lastContinuousLoginTimes[1] > 16 || this.lastContinuousLoginTimes[1] < 7)){
            this.lastContinuousLoginTimes = [2,day];
            this.saveOtherGameData()
        }
    }
}
